
/* <<< COPYRIGHT START >>>
 * Copyright 2006-Present OxygenSoftwareLibrary.com
 * Licensed under the GNU Lesser General Public License.
 * http://www.gnu.org/licenses/lgpl.html
 * 
 * @author: Ugorji Dick-Nwoke
 * <<< COPYRIGHT END >>>
 */


package oxygen.wiki.actions;

import java.util.HashMap;
import java.util.Map;

import oxygen.web.ViewContext;
import oxygen.web.WebInteractionContext;
import oxygen.web.WebLocal;
import oxygen.wiki.WikiCategoryEngine;
import oxygen.wiki.WikiConstants;
import oxygen.wiki.WikiEngine;
import oxygen.wiki.WikiLinkHolder;
import oxygen.wiki.WikiLocal;

/**
 * @author ugorji
 */
public class EditConfigAction extends GenericWikiWebAction {
  
  {
    setFlag(FLAG_ADMIN_ACTION);
  }

  public int render() throws Exception { 
    handleEditConfig();
    ViewContext tctx = WebLocal.getViewContext();
    tctx.setAttribute(WikiConstants.TEMPLATE_SHOWBORDERS_KEY, Boolean.valueOf(false));
    showJSPView("editconfig.jsp");
    return RENDER_COMPLETED;
  }
  
  private void handleEditConfig() throws Exception {
    WebInteractionContext request = WebLocal.getWebInteractionContext();
    WikiLinkHolder lh = WikiLocal.getWikiLinkHolder();
    WikiCategoryEngine wcengine = WikiLocal.getWikiCategoryEngine();
    WikiEngine we = wcengine.getWikiEngine();
    String configfile = request.getParameter("configfile");
    String configtext = we.getWikiRuntimePersistenceManager().load(configfile);
    if(configtext == null) {
      configtext = "";
    }
    Map model = new HashMap();
    
    model.put("configfile", configfile);
    model.put("configtext", configtext);
    lh.setAttribute("wiki.model.editconfig", model);
  }

}

